package com.example.pomelo_home.dao;

import com.example.pomelo_home.entity.Activity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ActivityRepository extends JpaRepository<Activity,Integer> {
    //活动类型对应订单数量图表（管理）
    @Query(value ="SELECT a.activity_type, COUNT(ao.order_id) AS orderCount FROM activity a JOIN activityorder ao ON a.title = ao.activity_title GROUP BY a.activity_type", nativeQuery = true)
    List<Object[]> countOrdersByAllActivityTypes();
    //分页模糊查询活动名（管理）
    public Page<Activity> findByTitleLike(String title, Pageable pageable);
    //根据id查询活动信息（小程序）
    @Query(value = "SELECT * FROM activity WHERE activity_id=?", nativeQuery = true)
    public Activity findActivity(@Param("activity_id")Integer id);

}
